//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

import { WebviewWindow } from '@tauri-apps/api/webviewWindow';

export async function openBoardDrawWindow(boardId: string, drawId: string) {
    const label = `draw:${drawId}`;
    const oldWebview = await WebviewWindow.getByLabel(label);
    if (oldWebview != null) {
        await oldWebview.show();
        await oldWebview.setAlwaysOnTop(true);
        setTimeout(() => {
            oldWebview.setAlwaysOnTop(false);
        }, 200);
        return;
    }
    const webview = new WebviewWindow(label, {
        url: `/window/board/draw?boardId=${boardId}&drawId=${drawId}`,
        title: "画稿",
        center: true,
        width: 1500,
        height: 800,
        minWidth: 1500,
        minHeight: 800,
        decorations: false,
        alwaysOnTop: true,

        dragDropEnabled: false,
        devtools: true,
    });
    webview.once('tauri://error', function (e) {
        console.log(e);
    })
}